const mysql = require('mysql');
const configure = require('../bin/Configure.js');

const pool = mysql.createPool(configure.dbOptions);

const query = sql => new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
        if (err) {
            reject(err);
            return;
        }
        connection.query(sql, (error, results, fields) => {
            connection.release();
            if (err) reject(err);
            else resolve({ results, fields });
        });
    });
});

exports.query = query;
